﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 信息引用 数据类
    /// </summary>
    public class DocRefImp
    {
        public DocRefImp()
        {
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2014-08-07</date>
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.DocRefImp DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.DocRefImp model = new ElingOA6_Admin_DSJCJ.Model.DocRefImp();
            if (row != null)
            {
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = decimal.Parse(row["FDocId"].ToString());
                }
                if (row["FDocClsCd"] != null)
                {
                    model.FDocClsCd = row["FDocClsCd"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FImpEmplNo"] != null)
                {
                    model.FImpEmplNo = row["FImpEmplNo"].ToString();
                }
                if (row["FImpDeptNo"] != null)
                {
                    model.FImpDeptNo = row["FImpDeptNo"].ToString();
                }
                if (row["FImpDate"] != null && row["FImpDate"].ToString() != "")
                {
                    model.FImpDate = DateTime.Parse(row["FImpDate"].ToString());
                }
                if (row.Table.Columns.Contains("FTitle"))
                {
                    if (row["FTitle"] != null)
                    {
                        model.FTitle = row["FTitle"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FDocClsName"))
                {
                    if (row["FDocClsName"] != null)
                    {
                        model.FDocClsName = row["FDocClsName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FImpDocClsCd"))
                {
                    if (row["FImpDocClsCd"] != null)
                    {
                        model.FImpDocClsCd = row["FImpDocClsCd"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FImpDocClsName"))
                {
                    if (row["FImpDocClsName"] != null)
                    {
                        model.FImpDocClsName = row["FImpDocClsName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FDeptName"))
                {
                    if (row["FDeptName"] != null)
                    {
                        model.FDeptName = row["FDeptName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FEmpName"))
                {
                    if (row["FEmpName"] != null)
                    {
                        model.FEmpName = row["FEmpName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FPubDate"))
                {
                    if (row["FPubDate"] != null && row["FPubDate"].ToString() != "")
                    {
                        model.FPubDate = DateTime.Parse(row["FPubDate"].ToString());
                    }
                }
                if (row.Table.Columns.Contains("DocRefKeyValue"))
                {
                    if (row["DocRefKeyValue"] != null)
                    {
                        model.DocRefKeyValue = row["DocRefKeyValue"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FImpEmpName"))
                {
                    if (row["FImpEmpName"] != null)
                    {
                        model.FImpEmpName = row["FImpEmpName"].ToString();
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 取消信息引用
        /// <creator>wangl</creator>
        /// <date>2014-08-07</date> 
        /// </summary>
        /// <param name="docIdList">信息编号列表</param>
        /// <param name="docClsCdList">信息引用编号</param>
        public void CancelDocumentRef(List<decimal> docIdList, List<string> docClsCdList, string entityNo)
        {
            List<CommandInfo> commandInfoList = new List<CommandInfo>();
            CommandInfo commandInfo = new CommandInfo();
            StringBuilder strSql = new StringBuilder();
            SqlParameter[] parameters = new SqlParameter[] { };
            for (int i = 0; i < docIdList.Count; i++)
            {

                strSql = new StringBuilder();
                strSql.Append("delete from t_DocRefImp ");
                strSql.Append(" where FDocId=@FDocId and FDocClsCd=@FDocClsCd and FEntityNo=@FEntityNo ");
                parameters = new SqlParameter[]{
					new SqlParameter("@FDocId", SqlDbType.Decimal,9),
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)			};
                parameters[0].Value = docIdList[i];
                parameters[1].Value = docClsCdList[i];
                parameters[2].Value = entityNo;

                commandInfo = new CommandInfo(strSql.ToString(), parameters);
                commandInfoList.Add(commandInfo);
            }
            if (commandInfoList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(commandInfoList);
            }
        }
    }
}
